package com.poly.system.controller;

import com.poly.common.core.domain.R;
import com.poly.common.core.utils.poi.ExcelUtil;
import com.poly.common.core.validate.Add;
import com.poly.common.core.validate.Update;
import com.poly.common.core.web.controller.BaseController;
import com.poly.common.core.web.page.Pagination;
import com.poly.common.core.web.page.TableData;
import com.poly.common.log.annotation.Log;
import com.poly.common.log.enums.BusinessType;
import com.poly.common.security.annotation.RequiresPermissions;
import com.poly.system.domain.SysClientVersion;
import com.poly.system.pojo.dto.SysClientVersionDTO;
import com.poly.system.pojo.query.SysClientVersionQuery;
import com.poly.system.pojo.vo.SysClientVersionVO;
import com.poly.system.service.ISysClientVersionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 客户端版本Controller
 * 
 * @author poly
 * @date 2023-09-26
 */
@Api(tags = "客户端版本")
@RestController
@RequestMapping("/version")
public class SysClientVersionController extends BaseController
{
    @Autowired
    private ISysClientVersionService sysClientVersionService;

    /**
     * 查询客户端版本分页
     */
    @ApiOperation("查询客户端版本分页")
    @RequiresPermissions("system:version:list")
    @GetMapping("/queryPage")
    public R<Pagination<SysClientVersionVO>> queryPage(SysClientVersionQuery query) {
        return R.ok(sysClientVersionService.queryPage(query));
    }

    /**
     * 查询客户端版本列表
     */
    @ApiOperation("查询客户端版本列表")
    @RequiresPermissions("system:version:list")
    @GetMapping("/list")
    public R<List<SysClientVersionVO>> list(SysClientVersionQuery query)
    {
        return R.ok(sysClientVersionService.list(query));
    }

    /**
     * 导出客户端版本列表
     */
    @ApiOperation("导出客户端版本列表")
    @RequiresPermissions("system:version:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysClientVersionQuery query)
    {
        List<SysClientVersionVO> list = sysClientVersionService.list(query);
        ExcelUtil<SysClientVersionVO> util = new ExcelUtil<SysClientVersionVO>(SysClientVersionVO.class);
        util.exportExcel(response, list, "客户端版本数据");
    }

    /**
     * 获取客户端版本详细信息
     */
    @ApiOperation("获取客户端版本详细信息")
    @RequiresPermissions("system:version:query")
    @GetMapping(value = "/{id}")
    public R<SysClientVersion> getInfo(@PathVariable("id") Long id)
    {
        return R.ok(sysClientVersionService.get(id));
    }

    /**
     * 新增客户端版本
     */
    @ApiOperation("新增客户端版本")
    @Log(title = "客户端版本管理", businessType = BusinessType.INSERT)
    @RequiresPermissions("system:version:add")
    @PostMapping
    public R add(@RequestBody @Validated({Add.class}) SysClientVersionDTO dto) {
        return sysClientVersionService.add(dto);
    }

    /**
     * 修改客户端版本
     */
    @ApiOperation("修改客户端版本")
    @Log(title = "客户端版本管理", businessType = BusinessType.UPDATE)
    @RequiresPermissions("system:version:edit")
    @PutMapping
    public R edit(@RequestBody @Validated({Update.class}) SysClientVersionDTO dto) {
        return sysClientVersionService.update(dto);
    }

    /**
     * 删除客户端版本
     */
    @ApiOperation("删除客户端版本")
    @Log(title = "客户端版本管理", businessType = BusinessType.DELETE)
    @RequiresPermissions("system:version:remove")
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return toResult(sysClientVersionService.deleteByIds(ids));
    }
}
